package cn.edu.lingnan.before.controller;

import cn.edu.lingnan.before.serivce.GoodsTableService;
import cn.edu.lingnan.before.serivce.UserService;
import cn.edu.lingnan.common.JSONResult;
import cn.edu.lingnan.common.TimeKeep;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class UserController {
    @Resource
    private UserService userService;
    @Resource
    private GoodsTableService goodsTableService;
    @ResponseBody  //将指定类型的数据转成json返回给浏览器
    @PostMapping("/checkEmail")
    public JSONResult<Void> checkEmail(String email){
            return userService.checkEmailService(email);
    }
    @ResponseBody
    @PostMapping("/checkPwd")
    public JSONResult<Void> checkPwd(String password,String confirmPwd){
        return userService.checkPasswordAndConfirmPwd(password,confirmPwd);
    }
    /*
    * 发送邮箱验证码
    * */
    @ResponseBody
    @PostMapping("/sendEmail")
    public JSONResult<Void> sendEmail(String email, HttpSession session){

        return userService.sendEmail(email,session);
    }
    @ResponseBody
    @PostMapping("/checkEmailCode")
    public JSONResult<Void> checkEmailCode(String emailCode,HttpSession session){
        return userService.checkEmailCode(emailCode,session);
    }
    //注册
    @ResponseBody
    @PostMapping("/doReg")
    public JSONResult<Void> doReg(String email,String password,
                                  String confirmPwd,String emailCode,HttpSession session){
        return userService.doReg(email,password,confirmPwd,emailCode,session);
    }

    //检查登录邮箱
    @PostMapping("/checkLoginEmail")
    @ResponseBody
    public JSONResult<Void> checkLoginEmail(String email){
       return userService.checkLoginEmail(email);
    }

//    检查登录
    @PostMapping("/doLogin")
    @ResponseBody
    public JSONResult<Void> doLogin(String email,String password,
                                    String code,HttpSession session){
        return userService.doLogin(email,password,code,session);
    }

}
